﻿@{
    Layout = "~/Views/Shared/_detailBase.cshtml";
    <link href="~/SiteUI/Issue/Issue.css" rel="stylesheet" />
}

<div class="detail_LeftPart">
    <h3 id="detail_NO"></h3>
    <div id="detail_Proj" class="Selector"></div>
    <span id="detail_Importance"></span>
    <div id="detail_Cnt"></div>
    <div id="detail_PostInfo"></div>
</div>
<div class="detail_LeftPart">
    <div id="detail_TagsBar"><span class="detail_Tag">标签1</span><span class="detail_Tag">标签2</span></div>
</div>
<div class="detail_LeftPart" id="detail_CommentsLister">
    <div class="SectionTitle">回复&评论</div>
    <div id="btnNewComment">提交</div>
    <div id="pnlComment">

    </div>
</div>

<div id="tmp">
    @RenderPage("/SiteUI/wgBase.cshtml")
    @RenderPage("/SiteUI/Comment/wgComment.cshtml")
    @RenderPage("/SiteUI/Issue/wgIssue.cshtml")
</div>

<script>
    Env.MyProjs = [];

    function slctProj(_viewer, _ev) {
        var p = _ev.data;
        new AjaxHelper("get", "/Issue/SetProject", { 'objId': Env.Issue.IDStr, 'projId': p.IDStr },slctProjOK,p);
    };

    function slctProjOK(rtn, state) {
        if (rtn.IsPositive) {
            Env.Proj.text(this.State.Name);
        }
    };

    function setImportance(_ev) {
        new AjaxHelper("get", "/Issue/SetImportance", { 'objId': Env.Issue.IDStr, 'importance': _ev.Value });
    };
    
    function SubmitComment() {
        if (wgComment.chkComment.Check()) {
            var cmnt = wgComment.txbNewComment.val();
            new AjaxHelper("post", "/Comment/New", { cnt: cmnt, objType: 'Issue', objId: Env.Issue.IDStr }, getCommentEnd, Env.Issue.IDStr);
        }
    };
    function getCommentEnd(rtn, id) {
        if (rtn.IsPositive) {
            wgComment.lstComments.Prepend(rtn.Data.Comments ? rtn.Data.Comments : rtn.Data);
        }
    };

    $(function () {
        Env.Issue = '@ViewBag.Issue'.ToJSON();
        Env.Issue.Content = unescape(Env.Issue.Content);

        $("#detail_NO").text(Env.Issue.SerialNum);
        $("#detail_Cnt").html(Env.Issue.Content)
        $("#detail_PostInfo").html(Env.Issue.Poster + '  提交于' + Env.Issue.CreateTime);
        Env.Importance = new Rating($("#detail_Importance")).val(Env.Issue.Importance).on('valueChanged', setImportance);
        Env.Proj = $("#detail_Proj").text(Env.Issue.Project.Name);
        new Button($("#btnNewComment")).on('click', SubmitComment);
        wgComment.txbNewComment.dom().insertBefore($("#btnNewComment"));
        wgComment.lstComments.dom().appendTo($("#pnlComment"));

        //设置项目过滤控件
        Env.MyProjs = '@ViewBag.MyProjects'.ToJSON();
        if (Env.MyProjs) {
            Env.mnuUserProjs.Menu().Append(Env.MyProjs);
            Env.mnuUserProjs.Viewer(Env.Proj, slctProj);
        }
        if (Env.Issue.Comments) {
            wgComment.lstComments.Prepend(Env.Issue.Comments);
        }
    })
</script>
